<template>
	<view class="allBox">
		<view class="content">
			<image class="logo" src="https://i.postimg.cc/Zn0dzv8g/background.png"></image>
			<view class="text-area">
				<text class="title" @click="getLogin">{{token?'已登录':'点击登录'}}</text>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: uni.getStorageSync('token'),
			}
		},
		methods: {
			getLogin() {
				this.$request.post("/user/login/v1", {
						data: {
							employeeNum: 'A001',
							pwd: 'a123456'
						},
					})
					.then(res => {
						console.log(res, '登录成功')
						uni.showModal({
							title: res.data.msg,
							showCancel: false,
							content: res.data.msg
						})
						uni.setStorageSync(
							'userInfoPC', res
							.data.data); //存储pc账号信息

						uni.setStorageSync(
							'token', res
							.data.data
							.token);
						// 手动修改配置 setConfig方法会影响全局，请谨慎使用
						this.$request.setConfig({
							header: {
								'token': res.data.data.token, //全局token
								'Content-Type': 'application/json',
								'Access-Control-Allow-Origin': '*',
								'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, DELETE',
								'Access-Control-Allow-Headers': 'Content-Type'
							}
						})

					}).catch(err => {
						console.log('err', err);
					})
			}

		}
	}
</script>

<style scoped lang="scss">
	.allBox {
		width: 100%;
		height: 100vh;
		background-color: #f7f7f8;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 350px;
		width: 400px;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>